Skip to content

Conversation

@jakebailey
Copy link
Member

@jakebailey jakebailey commented Jan 31, 2026

If module is explicitly configured, we do what the config says (duh).

Otherwise, if target is ES5, then module=commonjs. If target is ES2015+, then module=es2015.

This PR changes the default module such that:

  • If target=esnext, then module=esnext.
  • If target>=es2022, then module=es2022.
  • If target>=es2020, then module=es2020.
  • If target>=es2015, then module=es2015.
  • Otherwise, module=commonjs.

This leads to potentially less strange/misaligned behavior.

Only one test changes. I could find which features each module mode enables to verify these rules, if desired.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates TypeScript’s implied default module compiler option to better align with the configured target, enabling more modern module semantics (e.g., top-level await) when targeting newer ECMAScript versions.

Changes:

  • Adjusts computed default for module based on target with new thresholds (es2020/es2022/esnext).
  • Updates a single baseline affected by the new default (top-level await now permitted under @target: esnext due to implicit module: esnext).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/compiler/utilities.ts Updates computed default module selection logic to track target more closely (es2015/es2020/es2022/esnext).
tests/baselines/reference/awaitInNonAsyncFunction.errors.txt Updates error baseline impacted by the new implicit module default enabling top-level await under @target: esnext.

Comment on lines +9006 to +9010
const target = _computedOptions.target.computeValue(compilerOptions);
if (target === ScriptTarget.ESNext) {
return ModuleKind.ESNext;
}
if (target >= ScriptTarget.ES2022) {
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change alters the implied module value based on target (including enabling top-level await for @target: esnext via the implicit module: esnext). It would be good to add a focused compiler test that explicitly asserts the new default mapping at the key boundaries (es2015/es2020/es2022/esnext), rather than relying on incidental baseline changes in unrelated tests.

Copilot generated this review using guidance from repository custom instructions.
@jakebailey
Copy link
Member Author

@typescript-bot test top800
@typescript-bot run dt

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 31, 2026

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
test top800 ✅ Started ✅ Results
run dt ✅ Started ✅ Results

@typescript-bot
Copy link
Collaborator

Hey @jakebailey, the results of running the DT tests are ready.

Everything looks the same!

You can check the log here.

@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the top 800 repos with tsc comparing main and refs/pull/63076/merge:

Everything looks good!

@github-project-automation github-project-automation bot moved this from Not started to Needs merge in PR Backlog Feb 2, 2026
@jakebailey jakebailey added this pull request to the merge queue Feb 2, 2026
Merged via the queue into microsoft:main with commit 97d51a7 Feb 2, 2026
38 of 39 checks passed
@jakebailey jakebailey deleted the module-default-esnext-ish branch February 2, 2026 17:21
@github-project-automation github-project-automation bot moved this from Needs merge to Done in PR Backlog Feb 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants